    //
//  SettingsViewController.m
//  pkphotomap
//
//  Created by Ed Mancebo on 3/30/11.
//  Copyright 2011 Personal. All rights reserved.
//

#import "SettingsViewController.h"
//#import "WebAuthController.h"

@implementation SettingsViewController

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/


// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {

	CGRect bounds = [[UIScreen mainScreen] bounds];
	
	// TODO: do not hard code this
	int tabBarHeight = 49;
	int statusBarHeight = 20;
	NSLog(@"Bounds = (%d, %d)", bounds.origin.x, bounds.origin.y);
	
	CGRect frame;
	frame.origin.x = 0;
	frame.origin.y = 0;
	frame.size.width = bounds.size.width;
	frame.size.height = bounds.size.height - tabBarHeight - statusBarHeight;
	
	tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStyleGrouped];
	tableView.delegate = self;
	tableView.dataSource = self;
	
	[self setView:tableView];
}


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	
	NSString *username = [[NSUserDefaults standardUserDefaults] stringForKey:@"username"];
	if (username == nil) {
		username = @"None";
	}
	
	UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"default"];
	cell.textLabel.text = username;
	cell.imageView.image = [UIImage imageNamed:@"buddyicon.jpg"];
	cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
	
	return [cell autorelease];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	return 1;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
	return @"Flickr account";
}

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {

	/*
	WebAuthController *webAuthController = [[WebAuthController alloc] init];
	[self.navigationController pushViewController:webAuthController animated:YES];
	[webAuthController autorelease];
	 */
	
	NSString *API_KEY = @"2099cafa3dc4df6fec7bb0e5d7aec256";
	
	NSString *urlString = 
		[NSString stringWithFormat:@"http://flickr.com/services/auth/fresh?api_key=%@&perms=write&api_sig=%@",
		 API_KEY, @"7575cf78a09e9ae84b5966eda7388ec9"];
	
	NSURL *loginURL = [NSURL URLWithString:urlString];
	[[UIApplication sharedApplication] openURL:loginURL];
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
